const { ethers, deployments, getNamedAccounts, network } = require("hardhat")
const { assert, expect } = require("chai")
const helpers = require("@nomicfoundation/hardhat-network-helpers")
const { devlopmentChains } = require("../helper-hardhat-config")

describe("test fundme contract...", async function () {
    let fundMe
    let fundMeSecondAccount
    let firstAccount
    let secondAccount
    let mockV3Aggregator
    this.beforeEach(async function () {
        await deployments.fixture(["all"])
        firstAccount = (await getNamedAccounts()).firstAccount
        secondAccount = (await getNamedAccounts()).secondAccount
        const fundMeDeployment = await deployments.get("FundMe")
        mockV3Aggregator = await deployments.get("MockV3Aggregator")

        fundMe = await ethers.getContractAt("FundMe", fundMeDeployment.address)
    })
    it("fundme success ", async function () {
        await fundMe.fund({ value: ethers.parseEther("0.1") })
        const balance = await fundMe.fundersToAmount(firstAccount)
        await expect(balance).to.equal(ethers.parseEther("0.1"))
    })
    it("window closed, refund", async function () {
        await fundMe.fund({ value: ethers.parseEther("0.1") })
        // make sure the window is closed
        await fundMe.withDraw()
        const balance = await fundMe.getBalance()

        await expect(balance).to.equal(ethers.parseEther("0"))
    })
})
